package com.bysj.studentsystem.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @ClassName SwaggerConfig
 * @Description:
 * @Author: xubao@wair.ac.cn
 * @Date: 2023/9/15 14:44
 */
@Component
@EnableSwagger2
public class SwaggerConfig {
    @Value("${swagger.flag}")
    private boolean flag;

    @Bean
    public Docket docket(){
        //指定在dev/test环境下使用swagger
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(flag) //关闭swagger,默认是true
                .select()
                //RequestHandlerSelectors：配置要扫描的方式，有basePackage("路径")、any():扫描全部，none():全部不扫描
                //RequestHandlerSelectors.withMethodAnnotation():扫描方法上的注解
                //.withClassAnnotation()：扫描类上的注解
                .apis(RequestHandlerSelectors.basePackage("com.bysj.studentsystem.controller"))//指定扫描的包
                .paths(PathSelectors.any())//设置请求路径，这里是带有hello的请求路径
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfo(
                "项目名称：student-system",
                "Api Documentation",
                "v1.0",
                "",
                null,
                "",
                "",
                new ArrayList()
        );
    }
}
